/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.config.javabeans;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.List;


/**
 * Class which corresponds to a "level" element in a view definition.<br>
 */
public class JBLevel implements Serializable
{
    /** Recursive type. */
    public static final String TYPE_RECURSIF = "recursif";
//DW/2630/BeginPatch
    /** Recursive type. */
    public static final String TYPE_RECURSIVE = "recursive";
//DW/2630/EndPatch

    /** Name of the level. */
    private String name;

    /** Type of level. */
    private String type;

    /** List of JBLevelRessource in the level. */
    private List levelRessourceList = new ArrayList();

    /** Creates new JBLevel. */
    public JBLevel()
    {
    }

    /**
     * Returns the list of resources in the level.
     * @return list of resources.
     */
    public List getLevelRessourceList()
    {
        return levelRessourceList;
    }

    /**
     * Adds a level resource.
     *
     * @param lr level resource to add.
     */
    public void addLevelRessource(JBLevelRessource lr)
    {
        this.levelRessourceList.add(lr);
    }

    /**
     * Displays a description of the level.
     *
     * @return String representation of the level description.
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        java.util.Iterator it = null;

        buf.append("      value = ");
        buf.append(name);
        buf.append(System.getProperty("line.separator"));

        buf.append("      type = ");
        buf.append(type);
        buf.append(System.getProperty("line.separator"));

        if (levelRessourceList != null)
        {
            buf.append("      List components of levelRessourceList = ");
            buf.append(System.getProperty("line.separator"));
            it = levelRessourceList.iterator();

            while (it.hasNext())
            {
                buf.append("      ...");
                buf.append(it.next());
                buf.append(System.getProperty("line.separator"));
            }
        }

        return buf.toString();
    }

    // end of toString method

    /**
     * Returns the name of the level.
     * @return name
     */
    public String getName()
    {
        return name;
    }

    /**
     * Sets the name of the level.
     * @param aname The name to set
     */
    public void setName(String aname)
    {
        this.name = aname;
    }

    /**
     * Returns the type of the level ("recursif" or empty).
     * @return "recursif" or empty
     */
    public String getType()
    {
        return type;
    }

    /**
     * Sets the type of the level.
     * @param atype The type to set: "recursif" or "recursive" or empty
     */
    public void setType(String atype)
    {
//DW/2630/BeginPatch
        if (atype.equals(TYPE_RECURSIVE) ||
            atype.equals(TYPE_RECURSIF))
        {
            //this.type = atype;
            this.type = TYPE_RECURSIF;
        }
//DW/2630/EndPatch
    }
}
